package com.sihai.core.utils;

import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

/**
 * utility class for Data
 */
public class DateUtils extends org.apache.commons.lang.time.DateUtils {

	private DateUtils() {
	}

	/**
	 * 往前后者往后推数月
	 *
	 * @param date date
	 * @param months how mony months
	 * @return Date
	 */
	public static Date addMonth(Date date, int months) {
		if (date == null) {
			throw new IllegalArgumentException("date can not be null");
		}
		Calendar calendar = new GregorianCalendar();
		calendar.setTime(date);
		calendar.add(Calendar.MONTH, months);
		return calendar.getTime();
	}

	/**
	 * todo:unit test 往前后者往后推数天
	 *
	 * @param date date
	 * @param days how mony days
	 * @return Date
	 */
	public static Date addDay(Date date, int days) {
		if (date == null) {
			throw new IllegalArgumentException("date can not be null");
		}
		Calendar calendar = new GregorianCalendar();
		calendar.setTime(date);
		calendar.add(Calendar.DATE, days);
		return calendar.getTime();
	}

	/**
	 * 获得天数
	 *
	 * @param date Date
	 * @return day of month
	 */
	public static int getDay(Date date) {
		Calendar calendar = new GregorianCalendar();
		calendar.setTime(date);
		return calendar.get(Calendar.DATE);
	}
}
